import request from "@/utils/request";
import {
  CourseForm,
  CoursePageVO,
  CourseQuery,
  Courseinfo,
  EditCourseForm,
} from "./types";
import { AxiosPromise } from "axios";

/**
 * 学习的课程分页列表
 *
 * @param queryParams
 */
export function getStudyCoursePage(
  queryParams: CourseQuery
): AxiosPromise<PageResult<CoursePageVO[]>> {
  return request({
    url: "/api/v1/system/course/study/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 课程分页列表
 *
 * @param queryParams
 */
export function getClassPage(
  queryParams: CourseQuery
): AxiosPromise<PageResult<CoursePageVO[]>> {
  return request({
    url: "/api/v1/system/course/page",
    method: "get",
    params: queryParams,
  });
}

// 修改课程
export function editCourse(data: EditCourseForm, courseId: number) {
  return request({
    url: "/api/v1/system/course/update",
    method: "post",
    params: {
      ...data,
      courseId,
    },
  });
}

/**
 * 进入课程主页面时加载课程信息
 */
export function getCourseInfo(courseId: number): AxiosPromise<Courseinfo> {
  return request({
    url: "/api/v1/system/course",
    method: "get",
    params: {
      courseId,
    },
  });
}

/**
 * 进入课程主页面时加载课程信息
 */
export function getTeachCourseInfo(courseId: number): AxiosPromise<Courseinfo> {
  return request({
    url: "/api/v1/system/course/courseInfo",
    method: "get",
    params: {
      courseId,
    },
  });
}

/**
 * 添加课程
 *
 * @param queryParams
 */
export function AddCourse(queryParams: CourseForm): AxiosPromise<void> {
  return request({
    url: "/api/v1/system/course/add",
    method: "post",
    data: queryParams,
  });
}

/**
 * 添加课程
 *
 * @param queryParams
 */
export function GetTeacherInfo(courseId: number) {
  return request({
    url: "/api/v1/system/course/roles",
    method: "get",
    params: {
      courseId,
    },
  });
}

/**
 * 删除课程
 */
export function deleteCourse(courseId: number) {
  return request({
    url: "/api/v1/system/course/delete",
    method: "delete",
    params: {
      courseId,
    },
  });
}

/**
 * 添加课程
 *
 * @param queryParams
 */
export function isValidCourseParamsApi(courseId: number) {
  return request({
    url: "/api/v1/system/course/authorization",
    method: "get",
    params: {
      courseId,
    },
  });
}

/**
 * 进入课程主页面时加载课程信息
 */
export function getCourseInfoApi(courseId: number): AxiosPromise<Courseinfo> {
  return request({
    url: "/api/v1/system/course",
    method: "get",
    params: {
      courseId,
    },
  });
}
